package com.lfs.market.controller.front;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.lfs.market.model.R;
import com.lfs.market.model.entity.ProductCollect;
import com.lfs.market.service.ProductCollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/collect")
@SaCheckLogin
public class ProductCollectController {
    @Autowired
    private ProductCollectService productCollectService;

    /**
     * 收藏商品
     *
     * @param collect
     * @return
     */
    @PostMapping
    public R create(@RequestBody ProductCollect collect) {
        productCollectService.collectProduct(collect);
        return R.ok();
    }

    /**
     * 取消收藏
     *
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public R delete(@PathVariable String id) {
        return productCollectService.delete(id);
    }

    /**
     * 查询收藏列表
     *
     * @return
     */
    @GetMapping("/list")
    public R<List<List<Object>>> list() {
        List list = productCollectService.getList();
        return R.ok(list);
    }
}
